
import datetime

import jwt

from app import myApp

jwtConfig=myApp.config['jwt']

class JwtUtils:

    @staticmethod
    def createUserToken(userid):
        now=datetime.datetime.now().timestamp()
        payload={'iss':jwtConfig["iss"],'exp':now+jwtConfig["expir"]*60,
                 'nbf':now,'iat':now,'userId':userid}
        return jwt.encode(payload=payload,key='secret',algorithm='HS256')
    
    @staticmethod
    def decodeToken(token,options={}):
        paylod=jwt.decode(token,key="secret",algorithms=["HS256"],options=options)
        return paylod


